new Vue({
	el: '#app',
	data: {
		uid: '',
		api_token: '',
		user: '',
		path: '',
		password: '',
		new_password: '',
		confirm: ''
	},
	mounted: function() {
		this.init();
	},
	methods: {
		init: function() {
			var self = this;
			self.uid = $api.getStorage('uid');
			self.api_token = $api.getStorage('api_token');
			if(self.uid) {
				self.getUserMsg();
			} else {
				apiready = function() {
					api.toast({
						msg: "未登录",
						duration: 2000,
						location: 'middle'
					});
					self.layout();
				};
			}
		},
		//登出
		layout: function() {
			api.openWin({
				name: 'login',
				url: '../login/login.html',
				reload: true,
				pageParam: {
					index: 4,
					type: 2
				}
			});
		},
		getUserMsg: function() {
			var self = this;
			apiready = function() {
				self.getMsg();
			};
		},
		//读取用户信息
		getMsg: function() {
			var self = this;
			console.log(self.uid);
			var data = {
				uid: self.uid,
				token: self.api_token
			};
			$.post(base + config.user_show, data, function(msg) {
				console.log(msg);
				if(msg.error == 0) {
					self.user = msg.data;
					self.path = msg.url;
				} else {
					console.log(self.error_msg);
					api.toast({
						msg: self.error_msg,
						duration: 2000,
						location: 'middle'
					});
				}
			}, 'json');
		},
		//修改密码
		editPassword: function() {
			var self = this;
			console.log(self.uid);
			var data = {
				confirm: self.confirm,
				uid: self.uid,
				token: self.api_token,
				new_password: self.new_password,
				password: self.password
			};
			$.post(base + config.user_update_password, data, function(msg) {
				console.log(msg);
				if(msg.error == 0) {
					$api.clearStorage();
					self.layout();
				} else {
					console.log(msg.error_msg);
					api.toast({
						msg: msg.error_msg,
						duration: 2000,
						location: 'middle'
					});
				}
			}, 'json');
		}
	}
})